package com.compass.doctor.ui.home

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.DisplayMetrics
import com.compass.doctor.base.BaseVBActivity
import com.compass.doctor.databinding.ActivityVaServiceDetailsBinding
import com.compass.framework.ext.gone
import com.compass.framework.ext.onClick
import com.compass.framework.ext.visible
import com.compass.framework.model.VAServiceBean

/**
 * Description： 服务详情
 * Date:2024/7/28 13:29
 */
class VAServiceDetailsActivity : BaseVBActivity<ActivityVaServiceDetailsBinding>() {

    companion object {
        fun start(context: Context, vaServiceBean: VAServiceBean?) {
            val intent = Intent(context, VAServiceDetailsActivity::class.java)
            intent.putExtra("vaServiceBean", vaServiceBean)
            context.startActivity(intent)
        }
    }

    private var vaServiceBean: VAServiceBean? = null

    override fun initView(savedInstanceState: Bundle?) {
        vaServiceBean = intent.serializable("vaServiceBean")
        mBinding.tvContent.getSettings().useWideViewPort = true
        mBinding.tvContent.getSettings().loadWithOverviewMode = true
        mBinding.tvContent.setInitialScale(getRecommendedScale());


    }

    private fun  getRecommendedScale():Int {
        val displayMetrics = resources.displayMetrics
        val screenDensity = displayMetrics.density

        // 根据屏幕密度设置推荐缩放级别
        val recommendedScale = when (screenDensity.toInt()) {
            DisplayMetrics.DENSITY_LOW as Int -> 75
            DisplayMetrics.DENSITY_MEDIUM as Int -> 100
            DisplayMetrics.DENSITY_HIGH as Int -> 150
            else -> 100
        }
        return recommendedScale;
    }
    override fun initData() {
        vaServiceBean?.let {
            it.swiper_img?.let { imgList ->
                mBinding.bannerHome.visible()
                mBinding.bannerHome.setData(imgList)
            } ?: kotlin.run {
                mBinding.bannerHome.gone()
            }

            mBinding.tvTitle.text = it.name
            mBinding.tvSpace.text = "规格：${it.spec}"
            mBinding.tvPrice.text = "￥${it.price}"
            mBinding.tvContent.loadData(it.content, "text/html", "UTF-8")
        }
    }
    override fun intListener() {
        mBinding.tvShare.onClick {

            VAServiceCodeActivity.start(this,vaServiceBean)
        }
    }


}
